package com.gyg.controller;


import com.gyg.domain.CloudUser;
import com.gyg.returns.RespEntity;
import com.gyg.service.CloudUserService;
import com.gyg.vo.param.LoginParam;
import com.gyg.vo.param.RegisterParam;
import com.gyg.vo.param.UserParam;
import com.gyg.vo.param.UserPwdParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 用户信息表 前端控制器
 * </p>
 *
 * @author gyg
 * @since 2021-02-20
 */
@RestController
@RequestMapping("/cloud-user")
@Slf4j
@Api(value = "用户操作", tags = "用户操作")
public class CloudUserController {

    @Resource
    private CloudUserService cloudUserService;

    @GetMapping("/check")
    @ApiOperation(value = "校验账号")
    @ApiImplicitParam(paramType = "query", dataType = "String", name = "username", value = "账号", required = true)
    public RespEntity checkUsername(@RequestParam(value = "username", required = true) String username) {
        RespEntity respEntity = cloudUserService.checkUsername(username);
        return respEntity;
    }

    @PostMapping("/register")
    @ApiOperation(value = "新用户注册")
    public RespEntity register (@RequestBody RegisterParam registerParam) {
        RespEntity respEntity = cloudUserService.register(registerParam);
        return respEntity;
    }

    @PostMapping("login")
    @ApiOperation(value = "用户登陆")
    public RespEntity<CloudUser> login(@RequestBody LoginParam loginParam) {
        RespEntity<CloudUser> respEntity = cloudUserService.login(loginParam);
        return respEntity;
    }

    @PutMapping("/update")
    @ApiOperation(value = "编辑个人信息")
    public RespEntity updateUser(@RequestBody UserParam userParam) {
        RespEntity respEntity = cloudUserService.updateUser(userParam);
        return respEntity;
    }

    @PostMapping("/checkPwd")
    @ApiOperation(value = "校验旧密码")
    public RespEntity checkPassword(@RequestBody UserPwdParam userPwdParam) {
        RespEntity respEntity = cloudUserService.checkPassword(userPwdParam);
        return respEntity;
    }

    @PutMapping("/updatePwd")
    @ApiOperation(value = "修改密码")
    public RespEntity updatePassword(@RequestBody UserPwdParam userPwdParam) {
        RespEntity respEntity = cloudUserService.updatePassword(userPwdParam);
        return respEntity;
    }

    @GetMapping("/info")
    @ApiOperation(value = "用户信息")
    @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "userId", value = "用户id", required = true)
    public RespEntity<CloudUser> userInfo(@RequestParam(value = "userId", required = true) Integer userId) {
        RespEntity<CloudUser> respEntity = cloudUserService.userInfo(userId);
        return respEntity;
    }
}
